@extends('admin.layout')
@section('content')
<div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                MENU分类排序
                <small></small>
            </h1>
           
        </section>
 		<section class="content">
            <div class="row">
                <div class="col-xs-12">
					<div class="box">
                        <div class="box-header">
                            <h3 class="box-title">设置排序</h3>
                        </div><!-- /.box-header -->
							
                        <div class="box-body">
                          @if(session('info'))
                            <div class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <h4><i class="icon fa fa-warning"></i> 警告!</h4>
                                 <ul>
                                    {{ session('info') }}
                                 </ul>
                                </div>                              
                            @endif  
							
                            <table id="example1" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>分类名</th>
                                    <th>前台显示位置</th>
                                    <th>排序</th>
                                    
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $cate)
                                 @if($cate->menu_position == 1)
                                <tr>
                                    <td class="ids">{{ $cate -> id }}</td>
                                    <td class="name">{{ $cate -> name }}</td>
                                    <td class="position">MENU</td>
                                    <td class="px">{{ $cate -> menu_id }}</td>  
                                </tr>
                                @endif
                                @endforeach
                            </table>
                            <!-- <div class="container">
  							  @foreach ($data as $cate)
     							
 						      @endforeach
							</div> -->

							{!! $data->appends($request)->links() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
  </div><!-- /.content-wrapper -->
  <!-- 状态启用/禁用ajax -->
<script type="text/javascript">

window.onload = function()
{

	$.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }


});

//发送ajax
		function dblClick()
		{
					//获取当前对象
				var t = $(this);
				//获取id 和 username
				var id = $(this).parent().find(".ids").html();
				var oldName = $(this).html();

				// 设置input框
				var inpt = $("<input type='text' style='width:20px;'/>");
				inpt.val(oldName);
				$(this).html(inpt);

				//获取焦点
				inpt.select();
				//失去焦点事件
				inpt.on('blur', function(){
					//获取新值
					var newName = inpt.val();

					//发送ajax
					$.ajax({
						url:"{{ url('/admin/cate/menupx') }}",
						type:"POST",
						data:{id:id, menu_id:newName},
						success:function(data){
								if(data == 0)
								{
									t.html(newName);
								}else if(data == 1)
								{
									t.html(oldName);
								}else
								{
									alert('序号已存在');
								}
						},
						dataType:'json'
					});
					//添加双击事件
					t.on('dblclick', dblClick);

				});
				//清双击事件
				$(this).unbind('dblclick');
		}

	//修改排序
	$(".px").on('dblclick',dblClick);

}
</script>
@endsection